#ifndef USERMANAGEMENT_H
#define USERMANAGEMENT_H

#include <QObject>
#include <QSqlDatabase>
#include <QMap>
#include <QMutex>

class UserManagement : public QObject
{
    Q_OBJECT
public:
    explicit UserManagement(QObject *parent = nullptr);
    ~UserManagement();

    // 获取最后一次操作的错误信息
    QString getLastError() const;

    // 创建用户表
    void createUserTable();

    // 用户登录
    bool login(const QString &username, const QString &password);

    // 用户注册
    bool registerUser(const QString &username, const QString &password, const QString &email, const QString &phone);

    // 根据用户名、手机或邮箱查询用户信息
    QMap<QString, QVariant> queryUserByUsernamePhoneMail(const QString &username, const QString &phone, const QString &email);

    // 根据用户名修改用户信息
    bool updateByUsername(const QString &oldUsername, const QString &newUsername, const QString &password, const QString &email, const QString &phone, const QString &role);

    // 根据用户名删除用户
    bool deleteUserByUsername(const QString &username);

private:
    QString m_lastError;
    QMutex m_mutex;
};

#endif // USERMANAGEMENT_H
